package com.quartet.modules.vehicle.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.quartet.modules.vehicle.dao.TPlatformEquipmentInformationDao;
import com.quartet.modules.vehicle.dto.TPlatformEquipmentInformationAddRequestDto;
import com.quartet.modules.vehicle.entity.TPlatformEquipmentInformation;
import com.quartet.modules.vehicle.service.TPlatformEquipmentInformationService;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 平台设备信息表(TPlatformEquipmentInformation)表服务实现类
 *
 * @author makejava
 * @since 2021-05-04 16:43:20
 */
@Service("tPlatformEquipmentInformationService")
public class TPlatformEquipmentInformationServiceImpl extends ServiceImpl<TPlatformEquipmentInformationDao, TPlatformEquipmentInformation> implements TPlatformEquipmentInformationService {

    /**
     * 添加平台设备信息
     * @param tPlatformEquipmentInformationAddRequestDto
     */
    @Override
    public void addPlatformEquipmentInformation(TPlatformEquipmentInformationAddRequestDto tPlatformEquipmentInformationAddRequestDto) {
        if (!ObjectUtils.isEmpty(tPlatformEquipmentInformationAddRequestDto)) {
            TPlatformEquipmentInformation tPlatformEquipmentInformation = BeanUtil.copyProperties(tPlatformEquipmentInformationAddRequestDto, TPlatformEquipmentInformation.class);
            this.baseMapper.insert(tPlatformEquipmentInformation);
        }
    }

    /**
     * 功能描述: 修改平台设备信息
     * @author huipanxing huipanxing@chinasofti.com
     * @date 2021/5/13 16:17
     * @param tPlatformEquipmentInformationAddRequestDto
     * @return void
     */
    @Override
    public void updatePlatformEquipmentInformation(TPlatformEquipmentInformationAddRequestDto tPlatformEquipmentInformationAddRequestDto) {
        if (!ObjectUtils.isEmpty(tPlatformEquipmentInformationAddRequestDto)) {
            TPlatformEquipmentInformation tPlatformEquipmentInformation = BeanUtil.copyProperties(tPlatformEquipmentInformationAddRequestDto, TPlatformEquipmentInformation.class);
            this.baseMapper.updateById(tPlatformEquipmentInformation);
        }
    }

    /**
     * 根据车辆编码删除平台设备信息
     * @param vehicleCode
     */
    @Override
    public void deletePlatformEquipmentInformation(String vehicleCode) {
        this.baseMapper.delete(new QueryWrapper<TPlatformEquipmentInformation>().lambda().eq(TPlatformEquipmentInformation::getVehicleCode,vehicleCode));
    }

    /**
     * 根据车辆编码查询平台设备信息
     * @param vehicleCode
     * @return
     */
    @Override
    public TPlatformEquipmentInformationAddRequestDto selectPlatformEquipmentInformation(String vehicleCode) {
        TPlatformEquipmentInformation tPlatformEquipmentInformation = this.baseMapper.selectOne(new QueryWrapper<TPlatformEquipmentInformation>().lambda().eq(TPlatformEquipmentInformation::getVehicleCode, vehicleCode));
        TPlatformEquipmentInformationAddRequestDto tPlatformEquipmentInformationAddRequestDto = BeanUtil.copyProperties(tPlatformEquipmentInformation, TPlatformEquipmentInformationAddRequestDto.class);
        return tPlatformEquipmentInformationAddRequestDto;
    }
}
